#include "mq_connection.hpp"

int main()
{
    // 实例化异步工作线程对象
    wsmq::AsyncWorker::ptr worker = std::make_shared<wsmq::AsyncWorker>();
    // 实例化连接对象
    wsmq::Connection::ptr connection = std::make_shared<wsmq::Connection>("127.0.0.1", 8085, worker);
    // 通过连接创建信道
    wsmq::Channel::ptr channel = connection->openChannel();
    google::protobuf::Map<std::string, std::string> tmp_map;
    // 1. 通过信道声明交换机exchange1，交换类型为广播交换
    channel->declareExchange("exchange1", wsmq::ExchangeType::TOPIC, true, false, tmp_map);
    // 2. 通过信道声明队列queue1
    channel->declareQueue("queue1", true, false, false, tmp_map);
    // 3. 通过信道声明队列queue2
    channel->declareQueue("queue2", true, false, false, tmp_map);
    // 4. 通过信道绑定exchange1-queue1，binding_key为queue1；
    channel->queueBind("exchange1", "queue1", "queue1");
    // 5. 通过信道绑定exchange1-queue2，binding_key为news.music.#
    channel->queueBind("exchange1", "queue2", "news.music.#");
    // 循环向交换机发送数据，验证结果
    for(int i = 1; i <= 10; i++)
    {
        wsmq::BasicProperties bp;
        bp.set_id(wsmq::UUIDHelper::uuid());
        bp.set_delivery_mode(wsmq::DeliveryMode::DURABLE);
        bp.set_routing_key("news.music.pop");
        channel->basicPublish("exchange1", &bp, "hello world-" + std::to_string(i));
    }
    // 关闭信道
    connection->closeChannel(channel);
    return 0;
}